package com.hospitalsystem.service.impl;

import com.hospitalsystem.dao.RefundRecordDao;
import com.hospitalsystem.entity.RefundRecord;
import com.hospitalsystem.service.RefundRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (RefundRecord)表服务实现类
 *
 * @author makejava
 * @since 2024-12-28 19:33:24
 */
@Service("refundRecordService")
public class RefundRecordServiceImpl implements RefundRecordService {
    @Resource
    private RefundRecordDao refundRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param  rRId
     * @return 实例对象
     */
    @Override
    public RefundRecord queryById(String rRId) {
        return this.refundRecordDao.queryById(rRId);
    }

    /**
     * 分页查询
     *
     * @param refundRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RefundRecord> queryByPage(RefundRecord refundRecord, PageRequest pageRequest) {
        long total = this.refundRecordDao.count(refundRecord);
        return new PageImpl<>(this.refundRecordDao.queryAllByLimit(refundRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param refundRecord 实例对象
     * @return 实例对象
     */
    @Override
    public RefundRecord insert(RefundRecord refundRecord) {
        this.refundRecordDao.insert(refundRecord);
        return refundRecord;
    }

    /**
     * 修改数据
     *
     * @param refundRecord 实例对象
     * @return 实例对象
     */
    @Override
    public RefundRecord update(RefundRecord refundRecord) {
        this.refundRecordDao.update(refundRecord);
        return this.queryById(refundRecord.getRRId());
    }

    /**
     * 通过主键删除数据
     *
     * @param  rRId
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String rRId) {
        return this.refundRecordDao.deleteById(rRId) > 0;
    }
}
